package com.scu.service;


import com.scu.dao.CommentDao;
import com.scu.dao.TopicDao;
import com.scu.pojo.Comment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
@Transactional
public class CommentServiceImpl implements CommentService{

    @Autowired
    private CommentDao commentDao;

    @Autowired
    private TopicDao topicDao;


    /**
     *   comment里面的parent_id是否为空交给前端控制
     * @param comment
     * @return
     */
    @Override
    public int postComment(Comment comment){
//        System.out.println("postComment");
        topicDao.addCommentNum(comment.getT_id());
//        System.out.println(comment.getT_id());
//        comment.setParent_id(null);
        commentDao.postComment(comment);
        return 0;
    }


    @Override
    public int redactComment(Comment comment){
        System.out.println("redactComment");
        System.out.println(comment);
        return commentDao.redactComment(comment.getC_id() + "");
    }

    @Override
    public List<Comment> getCommentList(Comment comment){
        System.out.println("getCommentList");
        System.out.println(comment);
        return commentDao.getCommentList(comment);
    }

    @Override
    public int removeComment(String c_id){
        System.out.println("removeComment");
        topicDao.subCommentNum(c_id);
        return commentDao.redactComment(c_id);
    }

    @Override
    public List<Comment> getMyComment(Comment comment){
        System.out.println("getMyComment");
        System.out.println(comment);
        return commentDao.getCommentList(comment);
    }

    @Override
    public List<Comment> getMyCommentByPage(Comment comment,int page,int limit){
        System.out.println(comment);

        return commentDao.getMyCommentByPage((page-1)*limit,limit,comment);
    }


}
